// ignore_for_file: unnecessary_const

import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_widget/custom/custom_appbar.dart'; //引入这个控件

// ignore: must_be_immutable
class SwiperList extends StatefulWidget {
  String name;
  SwiperList({Key? key, required this.name}) : super(key: key);

  @override
  State<SwiperList> createState() => _SwiperListState();
}

class _SwiperListState extends State<SwiperList> {
  @override
  List<Image> imgs = [
    //建立了一个图片数组
    Image.asset(
      "images/swiper1.png",
      fit: BoxFit.contain,
    ),
    Image.asset(
      "images/swiper2.png",
      fit: BoxFit.contain,
    ),
    Image.asset(
      "images/swiper3.png",
      fit: BoxFit.contain,
    ),
    Image.asset(
      "images/swiper4.png",
      fit: BoxFit.contain,
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(10.0),
              child: Container(
                height: 175,
                width: double.infinity,
                decoration: const BoxDecoration(
                    color: Colors.pinkAccent,
                    borderRadius: const BorderRadius.all(
                      const Radius.circular(5.0),
                    )),
                child: Swiper(
                  itemBuilder: (BuildContext context, int index) {
                    //条目构建函数传入了index,根据index索引到特定图片
                    return imgs[index];
                  },
                  itemCount: imgs.length,
                  autoplay: true,
                  pagination: const SwiperPagination(), //这些都是控件默认写好的,直接用
                  control: null,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
